package com.lcxw.hxzbapi.dao.mapper;

import com.lcxw.hxzbapi.entity.pojo.YwpdMember;
import java.util.List;
import java.util.Map;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Result;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
import org.springframework.stereotype.Component;
import org.springframework.stereotype.Service;

@Component
@Mapper
@Service
public interface YwpdMemberMapper {

    //插入用户
    @Insert("insert into ywpd_member("
        + "userid,  telephone, "
        + "username, nickname, "
        + "idcard, intro, realname, sex, "
        + "area, "
        + "province, city, birthday, "
        + "interest, password, regtime, "
        + "lastlogtime, lastlogip, roomid, "
        + "maxonline, sign, bakpicurl, "
        + "imgurl, vip, vipexpire, "
        + "goldkey, awexpire, "
        + "spendcoin, earnbean, beanbalance, "
        + "beanbalance2, beanbalance3, freezestatus, "
        + "offlinevideo, signature, qq, "
        + "address, daoju1, daoju1expire, "
        + "emceeagenttime,age,occupation,"
        + "school,realNameAuth,liveStatus,"
        + "longitude,latitude,"
        + "cancelled,openId"
        + ") "
        + "values("
        + "#{userId}, #{telephone}, "
        + "#{userName}, #{nickName}, "
        + "#{idCard}, #{intro}, #{realName}, "
        + "#{sex}, #{area}, "
        + "#{province}, #{city}, #{birthday}, "
        + "#{interest}, #{password}, #{regTime}, "
        + "#{lastLogTime}, #{lastLogIp}, #{roomId}, "
        + "#{maxOnline}, #{sign}, #{bakPicUrl}, "
        + "#{imgUrl}, #{vip}, #{vipExpire}, "
        + "#{goldKey}, #{awExpire}, "
        + "#{spendCoin}, #{earnBean}, #{beanBalance}, "
        + "#{beanBalance2}, #{beanBalance3}, #{freezeStatus}, "
        + "#{offlineVideo}, #{signature}, #{qq}, "
        + "#{address}, #{daoju1}, #{daoju1Expire}, "
        + "#{emceeAgentTime},#{age},#{occupation},"
        + "#{school},#{realNameAuth},#{liveStatus},"
        + "#{longitude},#{latitude},"
        + "#{cancelled},#{openId}"
        + ")")
    int addYwpdMember(YwpdMember ywpdMember) throws Exception;

    //查询用户通过id
    @Select("SELECT * FROM ywpd_member WHERE id = #{id}")
    YwpdMember selectYwpdMemberById(long id);

    //查询用户通过userId
    @Select("SELECT * FROM ywpd_member WHERE userid = #{userId}")
    YwpdMember selectYwpdMemberByUserId(long userId);

    //查询用户通过用户名
    @Select("SELECT * FROM ywpd_member WHERE username = #{userName}")
    YwpdMember selectYwpdMemberByUserName(String userName);

    //查询用户通过手机号码
    @Select("SELECT * FROM ywpd_member WHERE telephone = #{telephone}")
    YwpdMember selectYwpdMemberByTelephone(String telephone);

    //更新用户
    @Update("UPDATE ywpd_member SET id = #{id},telephone = #{telephone},"
        + "username = #{userName},nickname = #{nickName},idcard = #{idCard},"
        + "intro = #{intro},realname = #{realName},sex = #{sex},"
        + "area = #{area}, province = #{province},"
        + "city = #{city},birthday = #{birthday},interest = #{interest},"
        + "password = #{password},regtime = #{regTime},lastlogtime = #{lastLogTime},"
        + "lastlogip = #{lastLogIp},roomid = #{roomId},maxonline = #{maxOnline},"
        + "sign = #{sign},bakpicurl = #{bakPicUrl},imgurl = #{imgUrl},"
        + "vip = #{vip},vipexpire = #{vipExpire},goldkey = #{goldKey},"
        + "awexpire = #{awExpire},spendcoin = #{spendCoin},earnbean = #{earnBean},"
        + "beanbalance = #{beanBalance},beanbalance2 = #{beanBalance2},beanbalance3 = #{beanBalance3},"
        + "freezestatus = #{freezeStatus},offlinevideo = #{offlineVideo},signature = #{signature},"
        + "qq = #{qq},address = #{address},daoju1 = #{daoju1},"
        + "daoju1expire = #{daoju1Expire},emceeagenttime = #{emceeAgentTime},"
        + "age = #{age},occupation = #{occupation},school = #{school},"
        + "realNameAuth = #{realNameAuth} , liveStatus=#{liveStatus},cancelled=#{cancelled},"
        + "longitude = #{longitude} , latitude=#{latitude},"
        + "openId = #{openId}"
        + "  where userid = #{userId}")
    int updateYwpdMember(YwpdMember ywpdMember) throws Exception;

    //通过userId给用户添加虚拟货币数量，主要用于用户充值
    @Update("UPDATE ywpd_member SET earnBean = earnBean + #{coin}  where userId = #{userId}")
    int updateCoinByUserId(int coin, long userId);

    //通过userName给用户添加虚拟货币数量，主要用于管理员给用户加值
    @Update("UPDATE ywpd_member SET earnBean = earnBean + #{coin}  where userName = #{userName}")
    int updateCoinByUserName(int coin, String userName) throws Exception;

    //查询头像
    @Select("SELECT imgUrl from ywpd_member WHERE userId = #{userId}")
    String selectImgUrlByUserId(long userId) throws Exception;

    //条件查询用户
    @Select(
        "<script>" + "SELECT * FROM ywpd_member WHERE "
            + "<if test='fromRegTime!=null'>"
            + "regTime &gt;= #{fromRegTime} and "
            + "</if>"
            + "<if test='toRegTime!=null'>"
            + "regTime &lt;= #{toRegTime} and "
            + "</if>"
            + "<if test='sign!=null'>"
            + "sign=#{sign} and "
            + "</if>"
            + "<if test='liveStatus!=null'>"
            + "liveStatus=#{liveStatus} and "
            + "</if>"
            + "<if test='cancelled!=null'>"
            + "cancelled=#{cancelled} and "
            + "</if>"
            + "1=1"
            + " LIMIT #{pageIndex},#{pageSize} "
            + "</script>"
    )
    List<YwpdMember> selectMemberDynamic(String fromRegTime, String toRegTime, Integer sign,
        Integer liveStatus, Integer cancelled, int pageIndex, int pageSize) throws Exception;

    @Select("<script>" + "SELECT COUNT(*) FROM ywpd_member WHERE "
        + "<if test='fromRegTime!=null'>"
        + "regTime &gt;= #{fromRegTime} and "
        + "</if>"
        + "<if test='toRegTime!=null'>"
        + "regTime &lt;= #{toRegTime} and "
        + "</if>"
        + "<if test='sign!=null'>"
        + "sign=#{sign} and "
        + "</if>"
        + "<if test='liveStatus!=null'>"
        + "liveStatus=#{liveStatus} and "
        + "</if>"
        + "<if test='cancelled!=null'>"
        + "cancelled=#{cancelled} and "
        + "</if>"
        + "1=1"
        + "</script>")
    int selectCountOfMemberDynamic(String fromRegTime, String toRegTime, Integer sign,
        Integer liveStatus,
        Integer cancelled);


    @Select("SELECT * FROM ywpd_member WHERE openId=#{openId}")
    YwpdMember selectByopenId(String openId);

    /**
     * 查询经纬度信息
     */
    @Select("SELECT longitude,latitude FROM ywpd_member WHERE userId = #{userId}")
    Map selectLngAndLat(long userId);

    /**
     * 查询所有用户
     */
    @Select("SELECT * FROM ywpd_member")
    List<YwpdMember> selectAll();
}
